<template>
  <div class="record-item">
    <div class="fav-icon" @click="handleFav">
      <img :src="favBg" />
      {{ item.isFocus ? '已关注' : '关注' }}
    </div>
    <div class="content">
      <div class="title ellipsis">
        {{ item.gridName }}
      </div>
      <div class="sub-content">
        <div class="vid-type shrink-0">{{ item.videoType }}</div>
        <div class="camera-name ellipsis">{{ item.videoName }}</div>
      </div>
    </div>
    <div class="op-btn shrink-0" @click="handleView">查看</div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { showToast } from 'vant'
import VidServe from '@/api/vid.ts'
import fav from '../assets/icon-yiguanzhu.png'
import unFav from '../assets/icon-weiguanzhu.png'

const props = defineProps<{
  item: TypeVidItem
}>()

const favBg = computed(() => {
  return props.item.isFocus ? fav : unFav
})

const emit = defineEmits(['view', 'fav'])
const handleView = () => {
  emit('view', props.item)
}

const handleFav = () => {
  if (props.item.isFocus == 0) {
    VidServe.addFav([props.item.id]).then(() => {
      showToast('关注成功')
      emit('fav', props.item)
    })
  } else {
    VidServe.cancelFav([props.item.id]).then(() => {
      showToast('取消关注成功')
      emit('fav', props.item)
    })
  }
}
</script>

<style lang="less" scoped>
.record-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  background: #ffffff;
  height: 69px;
  margin-bottom: 10px;
  padding-right: 12px;

  .fav-icon {
    width: 46px;
    height: 100%;
    flex-shrink: 0;
    font-size: 11px;
    box-sizing: border-box;
    color: #000;
    text-align: center;
    position: relative;
    padding-top: 42px;

    img {
      position: absolute;
      left: 0px;
      top: 0px;
      width: 100%;
      height: 100%;
    }
  }
  .content {
    padding: 0 9px;
    flex-grow: 1;
    height: 100%;
    display: flex;
    justify-content: center;
    flex-direction: column;
    overflow: hidden;
    .title {
      color: #0e0d16;
      font-weight: bold;
      font-size: 16px;
      width: 230px;
    }

    .sub-content {
      margin-top: 12px;
      display: flex;
      .vid-type {
        color: #3a75c5;
        font-weight: medium;
        font-size: 13px;
        padding-right: 6px;
        margin-right: 6px;
        border-right: 0.5px solid #d9d9d9;
      }

      .camera-name {
        color: #0000007f;
        font-weight: medium;
        font-size: 13px;
      }
    }
  }

  .op-btn {
    border-radius: 15px;
    width: 48px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    background: #3a75c5;
    color: #ffffff;
    font-weight: medium;
    font-size: 12px;
  }
}
</style>
